
#ifndef __SDK_KEYVALUE__INCLUDE__
#define __SDK_KEYVALUE__INCLUDE__

#include <ctime>
#include "Stream.h"
#include "Utility/ErrorCode.h"

namespace nebula { namespace sdk {

class IKey;

class IValue
{
public:
	virtual ~IValue() {};

public:
	virtual IValue*           Clone               () = 0;

	virtual const char*       GetName             () = 0;
	virtual NEBULA_ERROR_CODE SetName             (const char*) = 0;

	virtual NEBULA_ERROR_CODE SetTextValue        (const char*  value) = 0;
	virtual NEBULA_ERROR_CODE SetIntValue         (const int    value) = 0;
	virtual NEBULA_ERROR_CODE SetDoubleValue      (const double value) = 0;
	virtual NEBULA_ERROR_CODE SetBoolValue        (const bool   value) = 0;
	virtual NEBULA_ERROR_CODE SetDateTimeValue    (const time_t value) = 0;

	virtual const char*       GetTextValue        () = 0;
	virtual const int         GetIntValue         () = 0;
	virtual const double      GetDoubleValue      () = 0;
	virtual const bool        GetBoolValue        () = 0;
	virtual const time_t      GetDateTimeValue    () = 0;

	virtual NEBULA_ERROR_CODE TryGetIntValue      (int    *value) = 0;
	virtual NEBULA_ERROR_CODE TryGetDoubleValue   (double *value) = 0;
	virtual NEBULA_ERROR_CODE TryGetBoolValue     (bool   *value) = 0;
	virtual NEBULA_ERROR_CODE TryGetDateTimeValue (time_t *value) = 0;

	virtual IValue*           GetNextValue        () = 0;
	virtual IValue*           GetPrevValue        () = 0;
	virtual IKey*             GetParentKey        () = 0;
};

class IKey
{
public:
	virtual ~IKey() {};

public:
	virtual IKey*             Clone               () = 0;
	virtual void              Clear               () = 0;

	virtual const char*       GetName             () = 0;
	virtual NEBULA_ERROR_CODE SetName             (const char*) = 0;

	virtual IKey*             GetParentKey        () = 0;
	virtual IKey*             GetNextKey          () = 0;
	virtual IKey*             GetPrevKey          () = 0;
	virtual IKey*             GetFirstChildKey    () = 0;
	virtual IKey*             GetLastChildKey     () = 0;
	virtual IKey*             GetNamedKey         (const char* name) = 0;

	virtual IKey*             AppendNamedKey      (const char* name) = 0;
	virtual IKey*             ReleaseNamedKey     (const char* name) = 0;
	virtual NEBULA_ERROR_CODE DeleteNamedKey      (const char* name) = 0;
	virtual IKey*             AppendKey           (IKey* key) = 0;
	virtual IKey*             ReleaseKey          (IKey* key) = 0;
	virtual NEBULA_ERROR_CODE DeleteKey           (IKey* key) = 0;

	virtual IValue*           GetNamedValue       (const char* name) = 0;
	virtual IValue*           GetFirstValue       () = 0;
	virtual IValue*           GetLastValue        () = 0;

	virtual NEBULA_ERROR_CODE DeleteNamedValue    (const char* name) = 0;
	virtual NEBULA_ERROR_CODE DeleteValue         (IValue*) = 0;

	virtual NEBULA_ERROR_CODE SetTextValue        (const char* name, const char*  value, bool auto_add) = 0;
	virtual NEBULA_ERROR_CODE SetIntValue         (const char* name, const int    value, bool auto_add) = 0;
	virtual NEBULA_ERROR_CODE SetDoubleValue      (const char* name, const double value, bool auto_add) = 0;
	virtual NEBULA_ERROR_CODE SetBoolValue        (const char* name, const bool   value, bool auto_add) = 0;
	virtual NEBULA_ERROR_CODE SetDateTimeValue    (const char* name, const time_t value, bool auto_add) = 0;

	virtual NEBULA_ERROR_CODE AppendTextValue     (const char* name, const char*  value) = 0;
	virtual NEBULA_ERROR_CODE AppendIntValue      (const char* name, const int    value) = 0;
	virtual NEBULA_ERROR_CODE AppendDoubleValue   (const char* name, const double value) = 0;
	virtual NEBULA_ERROR_CODE AppendBoolValue     (const char* name, const bool   value) = 0;
	virtual NEBULA_ERROR_CODE AppendDateTimeValue (const char* name, const time_t value) = 0;

	virtual const char*       GetTextValue        (const char* name) = 0;
	virtual const int         GetIntValue         (const char* name) = 0;
	virtual const double      GetDoubleValue      (const char* name) = 0;
	virtual const bool        GetBoolValue        (const char* name) = 0;
	virtual const time_t      GetDateTimeValue    (const char* name) = 0;

	virtual NEBULA_ERROR_CODE TryGetIntValue      (const char* name, int    *value) = 0;
	virtual NEBULA_ERROR_CODE TryGetDoubleValue   (const char* name, double *value) = 0;
	virtual NEBULA_ERROR_CODE TryGetBoolValue     (const char* name, bool   *value) = 0;
	virtual NEBULA_ERROR_CODE TryGetDateTimeValue (const char* name, time_t *value) = 0;

	virtual NEBULA_ERROR_CODE Serialize           (IOStream*) = 0;
	virtual NEBULA_ERROR_CODE UnSerialize         (IIStream*) = 0;
};

}} // namespace nebula::sdk

#endif //end of __SDK_KEYNODE__INCLUDE__

